class Exploitdb < Formula
  desc "Database of public exploits and corresponding vulnerable software"
  homepage "https://www.exploit-db.com/"
  url "https://github.com/offensive-security/exploitdb.git",
      tag:      "2022-08-10",
      revision: "a8cb58b3e52dd6397ccbb046e938711c19bf24f0"
  version "2022-08-10"
  license "GPL-2.0-or-later"
  head "https://github.com/offensive-security/exploitdb.git", branch: "master"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_monterey: "ad28e86e28d7e2d668b3b367be796a27c7be683c97bea36f218ae11fc5a5130b"
    sha256 cellar: :any_skip_relocation, arm64_big_sur:  "2120cfec8cd012080fb7165e7b50cdfe2c8fe58d398c752d265c4772ea51b648"
    sha256 cellar: :any_skip_relocation, monterey:       "8e649e997b93b656d1ea6f3094c0ec3aa8614672b11435dea67c596733a1cc54"
    sha256 cellar: :any_skip_relocation, big_sur:        "16916296949d725b437ee049aee36d5251ed6dfd175d9d882a444b0e0d3a68bb"
    sha256 cellar: :any_skip_relocation, catalina:       "4e27caaba9619e884783bffb02c7ebfcca3b2845f952ce99f0234b1d25fc971a"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "2cf7da41667500d671cf1f97b400097d392059646206e222f81f6f6a62156989"
  end

  def install
    inreplace "searchsploit",
              "rc_file=\"\"", "rc_file=\"#{etc}/searchsploit_rc\""

    optpath = opt_share/"exploitdb"
    inreplace ".searchsploit_rc" do |s|
      s.gsub! "\"/opt/exploitdb\"", optpath
      s.gsub! "\"/opt/exploitdb-papers\"", "#{optpath}-papers"
    end

    bin.install "searchsploit"
    etc.install ".searchsploit_rc" => "searchsploit_rc"

    pkgshare.install %w[.git exploits files_exploits.csv files_shellcodes.csv
                        shellcodes]
  end

  test do
    system "#{bin}/searchsploit", "sendpage"
  end
end
